package com.ywdj.framework.rest.v1;

import com.ywdj.framework.entity.sys.UserEntity;
import com.ywdj.framework.entity.common.RespEntity;
import com.ywdj.framework.service.UserService;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author darkevil
 */
@Slf4j
@RestController
@RequestMapping(value = "rest/v1")
public class UserController {
    @Autowired
    private UserService userService;

    @PreAuthorize("hasAuthority('ROLE_ADMIN')")
    @GetMapping(value = "users")
    public RespEntity<List<UserEntity>> listUsers() {
        val respEntity = new RespEntity<List<UserEntity>>();
        val userList = userService.listUsers();
        respEntity.setResultCode(1);
        respEntity.setResultMessage("SUCCESS");
        respEntity.setResultObj(userList);
        return respEntity;
    }
}
